﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MVC_Project.Model;
using MVC_Project.Dal.Systems;
using System.Runtime.InteropServices;

namespace MVC_Project.Bll.Systems
{
    public class UsersBll:BaseBll<Users>
    {
        public override void SetDal()
        {
            Dal = new UsersDal();
        }

        public List<Users> GetUsersPage(int page,int size,string name,out int count) {

            var users = Dal.Query();

            if (!string.IsNullOrWhiteSpace(name))
            {
                users = users.Where(u => u.name.Contains(name));
            }

            count = users.Count();

            var list = users.OrderBy(u => u.userID).Skip((page - 1) * size).Take(size).ToList();

            return list;
        }

        public Users GetUsersById(int id) {
            return Dal.Query().Where(u => u.userID == id).FirstOrDefault();
        }

        public Users Login(string name, string pwd) { 
            return Dal.Query().Where(u => u.loginName == name&&u.loginPwd==pwd).FirstOrDefault();
        }

    }
}
